<?php

$rows = array( array('材料编号','材料名称','品牌','规格','单位',
		'期初结存数量', '单价', '金额',  
		'本期入库数量', '单价', '金额',  
		'本期出库数量', '单价', '金额', 
		'期末结存数量', '单价', '金额', '备注' ) );
if($list){
    $wareheadtotal=0; $wht =0;
    $wareintotal=0; $wit =0;
    $wareouttotal=0; $wot =0;
    $waretailtotal=0; $wtt =0;
    
    foreach($list as $ware){
	$tmp = array($ware['sno'], $ware['name'], $ware['brand'], $ware['specific'], $ware['unit'],
				$ware['head']['bl_amount'],fnum($ware['head']['bl_price']),fnum($ware['head']['bl_total']));
	$wareheadtotal += $ware['head']['bl_total'];
        $wht+=$ware['head']['bl_amount'];
	if(!empty($ware['in'])){
		$tmp[] = $ware['in']['amount'];
		$tmp[] = fnum($ware['in']['price']);
		$tmp[] = fnum($ware['in']['total']);
                $wareintotal += $ware['in']['total'];
                $wit += $ware['in']['amount'];
	}
	else{
		$tmp[] = '';
		$tmp[] = '';
		$tmp[] = '';
	}
	
	if(!empty($ware['out'])){
		$tmp[] = $ware['out']['amount'];
		$tmp[] = fnum($ware['out']['price']);
		$tmp[] = fnum($ware['out']['total']);
                $wareouttotal += $ware['out']['total'];
                $wot += $ware['out']['amount'];
	}
	else{
		$tmp[] = '';
		$tmp[] = '';
		$tmp[] = '';
	}
	
	$tmp[] = $ware['tail']['bl_amount'];
	$tmp[] = fnum($ware['tail']['bl_price']);
	$tmp[] = fnum($ware['tail']['bl_total']);
        $waretailtotal += $ware['tail']['bl_amount'];
        $wtt += $ware['tail']['bl_total'];
	
	$tmp[] = ''; //备注
	
	$rows[] = $tmp;
    }
    
    $rows[] = array('合计','','','','',$wht,'',fnum($wareheadtotal),$wit,'',fnum($wareintotal),$wot,'',fnum($wareouttotal),$wtt,'',fnum($waretailtotal));
}
Exporter::csv($rows, '库存汇总');

?>
